package com.zjitc.backend_shop.service.Impl;

import com.zjitc.backend_shop.mapper.CategoryMapper;
import com.zjitc.backend_shop.pojo.Category;
import com.zjitc.backend_shop.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;
    @Override
    public List<Category> findAllCategory() {
        return categoryMapper.selectAll();
    }

    @Override
    public Category findCategoryById(Integer id) {
        return categoryMapper.selectByPrimaryKey(id);
    }

    @Override
    public int addCategory(Category category) {
        categoryMapper.insert(category);
        return category.getId();
    }

    @Override
    public int updateCategory(Category category) {
        return categoryMapper.updateByPrimaryKey(category);
    }

    @Override
    public int deleteCategory(Integer id) {
        return categoryMapper.deleteByPrimaryKey(id);
    }

}
